#!/usr/bin/env python3 
# -*- coding: UTF-8 -*-

'''
测试百度内容页
by lina
'''
from src.gui.page import base_page

class BaiduContent(base_page.BasePage):

	def __init__(self):
		super().__init__()

	"""
	刷新当前页面
	by lina
	"""
	def refresh_page(self):
		self.mlog.add_log('refresh_page','刷新百度内容')
		self.driver.refresh

	"""
	搜索功能测试
	content:搜索的内容
	by lina
	"""
	def seach_content(self,content):
		self.mlog.add_log('BaiduContent','seach_content','清空输入栏')
		self.driver.find_element_by_xpath("//input[@id='kw']").clear()
		self.mlog.add_log('BaiduContent','seach_content','输入要搜索的内容:'+content)
		self.driver.find_element_by_xpath("//input[@id='kw']").send_keys(content)
		super().delay_time()
		self.mlog.add_log('BaiduContent','seach_content','提交搜索')
		self.driver.find_element_by_xpath("//input[@id='su']").click()
		super().delay_time()

	"""
	获取搜索结果（demo只考虑第一页）
	page:页面 point:第几条信息
	by lina
	"""
	def get_search_result(self,page,point):
		self.mlog.add_log('BaiduContent','get_search_result','获取第'+str(page)+'页第'+str(point)+'条内容')
		content = self.driver.find_element_by_xpath("//div[@id='"+str(point)+"']/h3/a").text
		return content

	"""
	点击搜索结果（demo只考虑第一页）
	page:页面 point:第几条信息
	by lina
	"""
	def into_search_result(self,page,point):
		self.mlog.add_log('BaiduContent','into_search_result','点击第'+str(page)+'页第'+str(point)+'条内容')
		self.driver.find_element_by_xpath("//div[@id='"+str(point)+"']/h3/a").click()

